package com.caiback.mapper;

import com.caiback.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户映射器
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名和密码查询用户
     * @param user
     * @return
     */
    @Select("select * from users where username=#{username} and password=#{password}")
    User getByUsernameAndPassword(User user);

    /**
     * 用户列表
     * @return
     */
    @Select("select * from users")
    List<User> list();

    /**
     * 用户编辑资料
     * @param user
     * @return
     */
    @Update("update users set name=#{name}, userProfession=#{userProfession}, " +
            "userIntroduce=#{userIntroduce}, updateTime=now() where id=#{id}")
    void editPost(User user);

    /**
     * 用户资料
     * @param id
     */
    @Select("select * from users where id = #{id}")
    User getByUser(Integer id);
}
